<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../../../assets/docs.css" rel="stylesheet" type="text/css" media="screen" />
<title>MooTools 1.3 Documentation - Types/URI</title>
</head>

<body>
  <div class="doc">
    <div class="methods">
      <h4 class="menu-item"><a href="#URI">URI</a></h4>
      <div class="menu-item"><a href="#Usage">Usage</a></div>
      <div class="menu-item"><a href="#URI:toString">toString</a></div>
      <div class="menu-item"><a href="#URI:set">set</a></div>
      <div class="menu-item"><a href="#URI:get">get</a></div>
      <div class="menu-item"><a href="#URI:setData">setData</a></div>
      <div class="menu-item"><a href="#URI:getData">getData</a></div>
      <div class="menu-item"><a href="#URI:clearData">clearData</a></div>
      <div class="menu-item"><a href="#URI:go">go</a></div>
      <div class="menu-item"><a href="#URI:toURI">toURI</a></div>
      <h4 class="menu-item"><a href="#String">String</a></h4>
      <div class="menu-item"><a href="#String:toURI">toURI</a></div>
    </div>
    <div class="l-border r-border span-15 content">
      <h1 id="URI"><a href="#URI">Type: URI</a></h1>
      <p class="description">Provides numerous methods useful for managing URIs.</p>
      <h2 id="Usage"><a href="#Usage">Usage</a></h2>
      <p class="description">Pass a <em>string</em> to the URI subclass and it will extend it, returning a new string-like object with new methods useful for managing that URI.</p>
      <h3>Syntax</h3>
      <pre class="javascript"><span class="kw2">new</span> URI<span class="br0">(</span><span class="br0">[</span>strURI, options<span class="br0">]</span><span class="br0">)</span>;
</pre>
      <h3>Arguments</h3>
      <ol>
        <li>strURI - (<em>string</em>) the URI to parse into the class.</li>
        <li>options - (<em>object</em>) a key/value set of options.</li>
      </ol>
      <h3>Options</h3>
      <ul>
        <li>base - (<em>mixed</em>) A base href for the URI (defaults to the document base location). Can be a <em>string</em> or an instance of <em>URI</em>. This is used to interpret relative urls (for instance if you were to call <em>new URI('/foo/bar.html')</em> the class will infer that this path is relative to the current document base location).</li>
      </ul>
      <h3>Example</h3>
      <pre class="javascript"><span class="kw2">var</span> myURI = <span class="kw2">new</span> URI<span class="br0">(</span><span class="st0">'http://user:password@www.test.com:8383/the/path.html?query=value#anchor'</span><span class="br0">)</span>;
</pre>
      <h3>Returns</h3>
      <ul>
        <li> <em>URI</em> - (<em>string</em>; optional) - an instance of the URI class that has new methods useful for managing the URI. If not declared the window's current base location is used.</li>
      </ul>
      <h2 id="URI:toString"><a href="#URI:toString">URI Method: toString</a></h2>
      <p class="description">Returns the URI as a <em>string</em>.</p>
      <h3>Syntax</h3>
      <pre class="javascript">myURI.<span class="me1">toString</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">//"http://www.test.com...etc"</span>
</pre>
      <h3>Returns</h3>
      <ul>
        <li>(<em>string</em>) the unaltered url.</li>
      </ul>
      <h2 id="URI:set"><a href="#URI:set">URI Method: set</a></h2>
      <p class="description">Set's a portion of the URI to the specified value.</p>
      <h3>Syntax</h3>
      <pre class="javascript">myURI.<span class="me1">set</span><span class="br0">(</span>part, value<span class="br0">)</span>;

</pre>
      <h3>Arguments</h3>
      <ol>
        <li>type - (<em>string</em>, optional) url with a query string to parse; defaults to <em>window.location</em> </li>
      </ol>
      <h3>Example</h3>
      <pre class="javascript">myURI.<span class="me1">set</span><span class="br0">(</span><span class="st0">'scheme'</span>, <span class="st0">'https'</span><span class="br0">)</span>;
myURI.<span class="me1">set</span><span class="br0">(</span><span class="st0">'host'</span>, <span class="st0">'www.foo.com'</span><span class="br0">)</span>;

<span class="co1">//etc.</span>
</pre>
      <h3>Returns</h3>
      <ul>
        <li>(<em>URI</em>) This instance of <em>URI</em>.</li>
      </ul>
      <h3>Valid parts</h3>
      <ul>
        <li>scheme - (<em>string</em>) 'http', 'https', 'ftp', etc.</li>
        <li>user - (<em>string</em>) the username portion of the credentials</li>
        <li>password - (<em>string</em>) the password portion of the credentials</li>
        <li>host - (<em>string</em>) 'www.example.com', 'example.com', 'subdomain.example.com', etc.</li>
        <li>port - (<em>string</em> or <em>integer</em>) 80, 8080, etc.</li>
        <li>directory - (<em>string</em>) '/directory/'</li>
        <li>file - (<em>string</em>) 'file.html'</li>
        <li>query - (<em>string</em>) 'foo=bar&amp;something=else' (the <em>?</em> is added for you)</li>
        <li>fragment - (<em>string</em>)  'anAnchor' (the <em>#</em> is added for you)</li>
        <li>data - (<em>object</em>) an object of key/value pairs to set the query to (<em>{foo: 'bar', something: 'else'}</em>)</li>
      </ul>
      <h2 id="URI:get"><a href="#URI:get">URI Method: get</a></h2>
      <p class="description">Returns the current value for the specified portion of the URI.</p>
      <h3>Syntax</h3>
      <pre class="javascript">myURI.<span class="me1">get</span><span class="br0">(</span>part<span class="br0">)</span>;
</pre>
      <h3>Example</h3>
      <pre class="javascript">myURI.<span class="me1">get</span><span class="br0">(</span><span class="st0">'scheme'</span><span class="br0">)</span>; <span class="co1">//returns "http", for example</span>
myURI.<span class="me1">get</span><span class="br0">(</span><span class="st0">'host'</span><span class="br0">)</span>; <span class="co1">//returns "www.example.com", for example</span>
</pre>
      <h3>Returns</h3>
      <ul>
        <li> <em>mixed</em> - usually returns a <em>string</em>, but in the case of 'data' returns an <em>object</em>.</li>
      </ul>
      <h3>Valid parts</h3>
      <ul>
        <li>scheme - (returns <em>string</em>) 'http', 'https', 'ftp', etc.</li>
        <li>user - (<em>string</em>) the username portion of the credentials</li>
        <li>password - (<em>string</em>) the password portion of the credentials</li>
        <li>host - (returns <em>string</em>) 'www.example.com', 'example.com', 'subdomain.example.com', etc.</li>
        <li>port - (returns <em>string</em>) 80, 8080, etc.</li>
        <li>directory - (returns <em>string</em>) '/directory/'</li>
        <li>file - (returns <em>string</em>) 'file.html'</li>
        <li>query - (returns <em>string</em>) 'foo=bar&amp;something=else' (the <em>?</em> is added for you)</li>
        <li>fragment - (returns <em>string</em>)  'anAnchor' (the <em>#</em> is added for you)</li>
        <li>data - (returns <em>object</em>) an <em>object</em> of key/value pairs to set the query to (<em>{foo: 'bar', something: 'else'}</em>)</li>
      </ul>
      <h2 id="URI:setData"><a href="#URI:setData">URI Method: setData</a></h2>
      <p class="description">Sets the query string from an <em>object</em> (much like <em>myURI.set('data', obj)</em>) but also allows merging.</p>
      <h3>Syntax</h3>
      <pre class="javascript">myURI.<span class="me1">setData</span><span class="br0">(</span>data<span class="br0">[</span>, merge, part<span class="br0">]</span><span class="br0">)</span>;

</pre>
      <h3>Arguments</h3>
      <ol>
        <li>object - (<em>object</em>) the key/values you want to set for the query string</li>
        <li>merge - (<em>boolean</em>, optional) if <em>true</em> the values will be merged with the existing query string. Defaults to <em>false</em>.</li>
        <li>part - (<em>string</em>, optional) this defaults to 'query' for setting query string data to the URI, but you could, for example specify 'fragment' to assign query string data to the '#...' portion of the URI (which is useful in ajax applications that wish to store state in the URI without reloading the document).</li>
      </ol>
      <h3>Alternate Syntax</h3>
      <pre class="javascript">myURI.<span class="me1">setData</span><span class="br0">(</span>key, value<span class="br0">)</span>;
</pre>
      <h3>Alternate Syntax Arguments</h3>
      <ol>
        <li>key - (<em>string</em>) the key of the data which you wish to assign</li>
        <li>value - (<em>string</em> or <em>number</em>) the value you wish to assign</li>
      </ol>
      <h3>Returns</h3>
      <ul>
        <li>(<em>URI</em>) this instance of <em>URI</em> </li>
      </ul>
      <h3>Example</h3>
      <pre class="javascript">myURI.<span class="me1">setData</span><span class="br0">(</span>myObject<span class="br0">)</span>; <span class="co1">//same as myURI.set('data', myObject);</span>

myURI.<span class="me1">setData</span><span class="br0">(</span>myObject, <span class="kw2">true</span><span class="br0">)</span>; <span class="co1">//merges myObject w/ existing query values</span>
myURI.<span class="me1">setData</span><span class="br0">(</span><span class="st0">'foo'</span>, <span class="st0">'bar'</span><span class="br0">)</span>; <span class="co1">//sets foo=bar in the query string</span>

myURI.<span class="me1">setData</span><span class="br0">(</span><span class="br0">{</span>foo: <span class="st0">'bar'</span><span class="br0">}</span>, <span class="kw2">false</span>, <span class="st0">'fragment'</span><span class="br0">)</span>; <span class="co1">//adds #foo=bar to the url fragment</span>
</pre>
      <h2 id="URI:getData"><a href="#URI:getData">URI Method: getData</a></h2>
      <p class="description">Returns the query string values as an <em>object</em>. Same as <em>URI.get('data')</em>.</p>
      <h3>Syntax</h3>
      <pre class="javascript">myURI.<span class="me1">getData</span><span class="br0">(</span><span class="br0">[</span>key, part<span class="br0">]</span><span class="br0">)</span>;

</pre>
      <h3>Arguments</h3>
      <ol>
        <li>key - (<em>string</em>; optional) If specified, returns the value for the given key.</li>
        <li>part - (<em>string</em>; optional) If specified, returns the data from the given part (defaults to 'query'). This is useful if you choose to store data in the fragment (the '#...' part of the URI) which is useful in ajax applications that wish to store state in the URI without reloading the document.</li>
      </ol>
      <h3>Returns</h3>
      <ul>
        <li> <em>mixed</em> - the <em>string</em> value for the given key; if key is not specified, returns an <em>object</em> for all the query string values.</li>
      </ul>
      <h2 id="URI:clearData"><a href="#URI:clearData">URI Method: clearData</a></h2>
      <p class="description">Clears the query string values entirely.</p>
      <h3>Syntax</h3>
      <pre class="javascript">myURI.<span class="me1">clearData</span><span class="br0">(</span><span class="br0">)</span>;
</pre>
      <h2 id="URI:go"><a href="#URI:go">URI Method: go</a></h2>
      <p class="description">Loads the url into the document location.</p>
      <h3>Syntax</h3>
      <pre class="javascript">myURI.<span class="me1">go</span><span class="br0">(</span><span class="br0">)</span>;
</pre>
      <h2 id="URI:toURI"><a href="#URI:toURI">URI Method: toURI</a></h2>
      <p class="description">Returns the current instance of <em>URI</em>. Useful when a parameter type is known to be either string or URI.</p>
      <h3>Example</h3>
      <pre class="javascript"><span class="co1">// Accepts either a string or URI instance</span>
<span class="kw2">function</span><span class="br0">(</span>uri<span class="br0">)</span><span class="br0">{</span>
    <span class="kw1">this</span>.<span class="me1">filename</span> = uri.<span class="me1">toURI</span><span class="br0">(</span><span class="br0">)</span>.<span class="me1">get</span><span class="br0">(</span><span class="st0">'file'</span><span class="br0">)</span>;

<span class="br0">}</span>
</pre>
      <h1 id="String"><a href="#String">Type: String</a></h1>
      <p class="description">Adds a method to instantiate a <em>URI</em> instance from a string.</p>
      <h2 id="String:toURI"><a href="#String:toURI">String Method: toURI</a></h2>
      <p class="description">Returns a <em>URI</em> instance.</p>
      <h3>Syntax</h3>
      <pre class="javascript"><span class="st0">"http://www.domain.com/etc"</span>.<span class="me1">toURI</span><span class="br0">(</span><span class="br0">)</span>
</pre>
      <h3>Returns</h3>
      <ul>
        <li>an instance of URI</li>
      </ul>
    </div>
  </div>
<script type="text/javascript" src="../../../assets/mootools-core-1.3.js"></script>
<script type="text/javascript" src="../../../assets/mootools-more-smoothscroll.js"></script>
<script type="text/javascript" src="../../../assets/doc-assist.js"></script>
</body>
</html>
